﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.ComponentModel;
using FinPlusInterfaces;

namespace FinPlusCompCore
{
    public class FinPlusSimplex : FinPlusComponent
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }
        [State(Test = true)]
        public override string TestString { get { return Adapter.ToString(); } }
        public override IPods Adapter { get { return _adapter; } }

        private readonly IFinPlusComp _sourceConn;
        private readonly IPods _adapter;

        //construct
        public FinPlusSimplex(IFinPlusComp source)
        {
            _sourceConn = source;
            source.Adapter.PodUpdate += Pod_Updated;
            _adapter = source.Adapter.Clone();
        }

        //common control interface
        public override void Dispose()
        {
            if (_sourceConn != null)
                _sourceConn.Dispose();
        }

        private void Pod_Updated(object s, BeanEventArgs a)
        {
            _adapter[a.Bean.Index].BeanUpdate(_adapter, a);
        }
    }
}
